package com.zbkc.main;

import com.zbkc.util.AlertUtils;
import com.zbkc.util.MyApplication;
import com.zbkc.util.ThreadPoolFactory;
import com.zbkc.util.ToastUtil;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;

public class ServerActivity extends Activity implements View.OnClickListener {

	private final int SERVICE_SUCESS = 1;
	private EditText editTest;
	Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			default:
			case 1:
			}
			while (true) {
				AlertUtils.dismissLoadingDialog();
				return;
				// if (ServerActivity.this.result == 200) {
				// // ToastUtil.showToast(ServerActivity.this,
				// "服务器地址正确，赶紧登陆去吧！");
				// // InputManagerUtil.closeInput(ServerActivity.this.editTest);
				// } else {
				// // ServerActivity.this.editTest.setText("");
				// // ToastUtil.showToast(ServerActivity.this,
				// "服务器地址错误，请重新输入！");
				// }
			}
		}
	};
	private int result = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		MyApplication.getInstance().addActivity(this);
		init();
		bindView();
	}

	@Override
	protected void onResume() {
		/**
		 * 设置为竖屏
		 */
		if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		}
		super.onResume();
	}

	private void bindView() {
		this.editTest = ((EditText) findViewById(R.id.et_test));
		// this.editTest.setOnEditorActionListener(new EditorActionLisenter());
		findViewById(R.id.ll_test).setOnClickListener(this);
		findViewById(R.id.ll_save).setOnClickListener(this);
		findViewById(R.id.ll_exit).setOnClickListener(this);
	}

	private void init() {
		// String str = PreferenceUtils.getString("responsecode");
		// if ((str != null) && (str.equals("200"))) {
		// Intent localIntent = new Intent();
		// localIntent.setClass(this, LoginActivity.class);
		// startActivity(localIntent);
		// }
	}

	private void testServiceAddress() {
		final String str = this.editTest.getText().toString().trim();
		if (TextUtils.isEmpty(str)) {
			ToastUtil.showToast(this, "服务器地址不能为空");
			return;
		}
		AlertUtils.showLoadingDialog(this, "服务器地址检测中,请稍后...", true);
		ThreadPoolFactory.getInstance().execute(new Runnable() {
			public void run() {
				// ServerActivity.this.result = HttpUtil.postResultCode(str
				// + "csmpv4/mb/getui.js");
				// ServerActivity.this.handler.sendEmptyMessage(1);
			}
		});
	}

	public void onClick(View paramView) {
		switch (paramView.getId()) {
		case 2131296303:
			if (this.result == 200) {
				// PreferenceUtils.putString("address", this.editTest.getText()
				// .toString().trim());
				// PreferenceUtils.putString("responsecode", this.result);
				// Intent localIntent = new Intent();
				// localIntent.setClass(this, LoginActivity.class);
				// startActivity(localIntent);
				// return;
			}
			ToastUtil.showToast(this, "请先检测服务器地址再进行登录!");
			break;
		case 2131296304:
			finish();
			break;
		case R.id.ll_test:
			Intent intent = new Intent();
			intent.setClass(this, LoginActivity.class);
			startActivity(intent);
			break;
		}
		// testServiceAddress();
	}

	// class EditorActionLisenter implements TextView.OnEditorActionListener {
	// EditorActionLisenter() {
	// }
	//
	// // public boolean onEditorAction(TextView paramTextView, int paramInt,
	// // KeyEvent paramKeyEvent) {
	// // if (paramInt == 6) {
	// // .this.testServiceAddress();
	// // return true;
	// // }
	// // return false;
	// // }
	// }

}
